<?php
/**
 * @author     ：lhw
 * @date       ：Created in 2019/8/4 19:09
 */

namespace app\api\controller;

use app\api\model\OrderMaster as OrderMasterModel;
use app\api\service\UserOrderService;
use app\api\Utils\ReturnUtils;
use app\api\service\PayService;

class UserOrderController extends BaseController
{
    public function create($useris_id,$useris_address,$useris_phone,$hdfk,$items){
        return ReturnUtils::TrueResult(UserOrderService::create($useris_id,$useris_address,$useris_phone,$hdfk,$items));
    }

    public function all($useris_id,$state = 0){
        if($state == 0)
            return ReturnUtils::TrueResult(OrderMasterModel::where(['useris_id' => $useris_id])->select());
        else
            return ReturnUtils::TrueResult(OrderMasterModel::where(['useris_id' => $useris_id,'state' => $state])->select());
    }

    public function one($order_id){
//        $result = OrderMasterModel::where(['id' => $order_id])->find();
//        if($result['send_pharmacy'] == null){
//            return ReturnUtils::TrueResult(OrderMasterModel::where(['id' => $order_id])->with(['detail','detail.drug','detail.drug.img'])->find());
//        }
        return ReturnUtils::TrueResult(OrderMasterModel::where(['id' => $order_id])->with(['detail','detail.drug','detail.drug.img','send'])->find());
    }

    public function pay($order_id){
        $payserver = new PayService();

        $result = $payserver->pay($order_id);

        return ReturnUtils::TrueResult($result);
    }

}